<template>
  <div class="app-container">
    <!-- :stretch="true"  选项卡平铺 -->
    <el-tabs v-model="distributeActive" style="height: 100%;" @tab-click="tabClick">
      <el-tab-pane label="药品发放" name="0" style="height: 100%;overflow-y: auto;">
        <grant ref="grantRef" :medical-insurance-traceability-code="medicalInsuranceTraceabilityCode"/>
      </el-tab-pane>
      <el-tab-pane label="药品发放记录" name="1" style="height: 100%;overflow-y: auto;">
        <lssued-grant ref="lssuedGrantRef" :medical-insurance-traceability-code="medicalInsuranceTraceabilityCode"/>
      </el-tab-pane>
      <el-tab-pane label="药品退药记录" name="2" style="height: 100%;overflow-y: auto;">
        <return-grant ref="returnGrantRef" :medical-insurance-traceability-code="medicalInsuranceTraceabilityCode"/>
      </el-tab-pane>
      <!-- <el-tab-pane name="2" label="门诊退费">
          <outpatient-refund />
      </el-tab-pane>
      <el-tab-pane name="3" label="Role">Role</el-tab-pane>
      <el-tab-pane name="4" label="Task">Task</el-tab-pane> -->
    </el-tabs>
  </div>
</template>

<script setup lang="ts">
import {useDictStoreHook} from "@/store/modules/dict";
import {useUserStoreHook} from "@/store/modules/user";
import grant from './grant.vue';
import lssuedGrant from './issuedGrant.vue';
import returnGrant from './returnGrant.vue';
import {selectConfigByCache} from "@/api/system/orgConfig.ts";

const dictStore = useDictStoreHook();
const useUserStore = useUserStoreHook();
const {proxy} = getCurrentInstance() as any;
const currentSelectDept = proxy.$currentSelectDept
const distributeActive = ref("0")
const grantRef = ref()
const returnGrantRef = ref()
const lssuedGrantRef = ref()
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;
/**
 * 医保-药品销售、入库追溯码是否必填 Y 必填 N不必填
 */
const medicalInsuranceTraceabilityCode = ref("N")

/**
 * tab页点击事件
 * @param obj
 */
function tabClick(obj: any) {
  const objThis = toRaw(obj)
  if (objThis.props.name === '0') {
    grantRef.value.handleQuery()
  } else if (objThis.props.name === '1') {
    lssuedGrantRef.value.inoroutFlagChange("4")
  } else if (objThis.props.name === '2') {
    returnGrantRef.value.handleQuery()
  }
}


/**
 * 通过orgId key获取对应的机构参
 */
function selectConfigByCacheFun() {
  // 是否启用电子发票流程
  selectConfigByCache(userInfo.orgId, "medical.insurance.traceabilityCode").then((res => {
    medicalInsuranceTraceabilityCode.value = res.data.configValue
  }))
}

onMounted(() => {
  nextTick(() => {
    grantRef.value.handleQuery()
  })
  selectConfigByCacheFun()
})

</script>


<script lang="ts">
export default {
  name: "DrugDistributeMedication"
}
</script>

<style scoped>
:deep(.el-tabs__item) {
  min-width: 200px;
  height: 30px;
}

:deep(.el-tabs__content) {
  height: calc(100% - 30px);
}

:deep(.el-tabs__nav-scroll) {
  background-color: #ffffff;
}

:deep(.el-tabs__header) {
  margin: 0 0 0px;
  box-shadow: 0 0 18px 0 #878787;
}
</style>
